package finalproject.model.rooms;

import finalproject.config.Randomizer;
import finalproject.model.items.Coffee;
import finalproject.model.items.LectureItem;
import finalproject.model.player.ItemManager;
import finalproject.model.player.Player;
import finalproject.view.StringManager;

/**
 * the lunchroom
 * @author Yassine Tijaniqs
 *
 */
public class LunchRoom extends Room {

	/**
	 * The coffee you will find in the room
	 */
	private Coffee coffe;

	/**
	 * @param description the room description
	 */
	public LunchRoom(String description) {
		super(description,true);
		// TODO Auto-generated constructor stub
	}



	@Override
	public boolean doActivity(Player p) {
		if(this.coffe == null)
		{
			try
			{
				ItemManager manager = p.getItemHolder();
				int randomInt = Randomizer.getRandom().nextInt(manager.getWorkingManager().size());
				LectureItem lect = manager.getWorkingManager().getKey(randomInt);
				manager.getWorkingManager().eraseKey(manager.getWorkingManager().getKey(randomInt));
				p.getBook().removeLectureOf(lect.getLecture().getTitle());
				StringManager.outPut("dumber");
			}
			catch(Exception e)
			{
				StringManager.outPut("cantdumb");
			}
		}
		else
		{
			coffe.use(p);
		}
		return true;
	}

	@Override
	public boolean prepareActivity(Player p) {
		if(Randomizer.getRandom().nextInt(3) == 0)
		{
			this.coffe = null;
			return false;
		}
		else
		{
			this.coffe = new Coffee();
			return true;
		}
	}
	@Override
	public String toString()
	{
		if(coffe == null)
		{
			return super.toString() + ": " + StringManager.getString("lunchroomfoot");  
		}
		else
		{
			return super.toString() + ": " + StringManager.getString("lunchroomcoffee"); 
		}
	}

}
